package cn.edu.gzhu.workOrderManagement.util;

import cn.edu.gzhu.workOrderManagement.constants.RegexConstant;
import cn.edu.gzhu.workOrderManagement.constants.WorkOrderAlertLevelConstant;
import cn.edu.gzhu.workOrderManagement.pojo.dto.workOrder.WorkOrderCreateDto;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

import static cn.edu.gzhu.workOrderManagement.constants.WorkOrderTypeConstant.*;

public class WorkOrderUtil {


    /*
    public static List<Integer> validateWorkOrderFields(List<WorkOrderCreateDto> workOrderCreateDtos) {
        List<Integer> invalidIndexes = new ArrayList<>();

        for (int i = 0; i < workOrderCreateDtos.size(); i++) {
            WorkOrderCreateDto workOrderCreateDto = workOrderCreateDtos.get(i);
            //若预期结束时间早于当前之间
            if (workOrderCreateDto.getExpectedEndTime().isBefore( LocalDateTime.now())){
                invalidIndexes.add(i);
            }
            else if (isFieldsEmpty(workOrderCreateDto)) {
                invalidIndexes.add(i);//判断是否有空属性
            }
            else if (!workOrderCreateDto.getRequestIdCard().matches(RegexConstant.ID_CARD)) {
                invalidIndexes.add(i);//判断身份证号是否合法
            } else if (!isValidType(workOrderCreateDto.getType())) {
                invalidIndexes.add(i);//判断工单类型是否合法
            } else if (!isValidAlertLevel(workOrderCreateDto.getAlertLevel())) {
                invalidIndexes.add(i);//判断工单警告等级是否合法
            }


        }
        return invalidIndexes;
    }
*/
/*
    public static boolean isFieldsEmpty(WorkOrderCreateDto workOrderCreateDto) {
        return Stream.of(
                workOrderCreateDto.getRequestUser(),
                workOrderCreateDto.getRequestIdCard(),
                workOrderCreateDto.getLogicalCardNumber(),
                workOrderCreateDto.getType(),
                workOrderCreateDto.getCategory(),
                workOrderCreateDto.getHandler(),
                workOrderCreateDto.getTeamMember(),
                workOrderCreateDto.getCaseBatch(),
                workOrderCreateDto.getManualType(),
                workOrderCreateDto.getTitle()
        ).anyMatch(str -> str == null || str.trim().isEmpty()) ||
                workOrderCreateDto.getAlertLevel() == null ||
                workOrderCreateDto.getIsRegulatoryComplaint() == null ||
                workOrderCreateDto.getExpectedEndTime() == null;
    }
*/
    public static boolean isValidType(String workOrderType) {
        return Objects.equals(workOrderType, COMMON) ||
                Objects.equals(workOrderType, REPEAT) ||
                Objects.equals(workOrderType, MATERIAL);
    }

    public static Boolean isValidAlertLevel(Integer alertLevel) {
        return alertLevel != null &&
               alertLevel <= WorkOrderAlertLevelConstant.LOW &&
               alertLevel >= WorkOrderAlertLevelConstant.CRITICAL;
    }

}